#include<bits/stdc++.h>
using namespace std;
int T;
int a[20];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        int n;
        scanf("%d",&n);
        memset(a,0,sizeof a);
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        int mx=(1<<n)-1;
        int ans=0;
       for(int i=0;i<=mx;i++){
            int ls0=0,ls1=0;
            int cnt=0;
            for(int j=1;j<n;j++){
                int t=(i&(1<<j));
                if(t) cnt+=(a[ls1]==a[j])*a[j],ls1=j;
                else cnt+=(a[ls0]==a[j])*a[j],ls0=j;
            }
            ans=max(ans,cnt);
        }
        printf("%d\n",ans);
    }
    return 0;
}
